﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AAA.Forms.Components.MetaData;

namespace AAA.Forms.Components.Util
{
    public class ComboBoxUtil
    {
        public static void Clear(ComboBox cboSource)
        {
            while (cboSource.Items.Count > 0)
                cboSource.Items.RemoveAt(0);
        }

        public static void ResetComboBoxSelectedIndex(ComboBox cboSource)
        {
            if (cboSource.Items.Count > 0)
                cboSource.SelectedIndex = 0;
        }   
        public static void InitComboBoxValue(ComboBox cboSource, string strRange, int iInterval)
        {
            string[] strValues = strRange.Split('~');

            InitComboBoxValue(cboSource, int.Parse(strValues[0]), int.Parse(strValues[1]), iInterval);

        }

        public static void InitComboBoxValue(ComboBox cboSource, int iStart, int iEnd, int iInterval)
        {
            int iCount = (iEnd - iStart) / iInterval + 1;
            string[] strValues = new string[iCount];

            for (int i = 0; i < iCount; i++)
            {
                strValues[i] = (iStart + i * iInterval).ToString();
            }

            InitComboBoxValue(cboSource, strValues);
        }

        public static void InitComboBoxValue(ComboBox cboSource, string[] strTexts)
        {
            InitComboBoxValue(cboSource, strTexts, strTexts);
        }

        public static void InitComboBoxValue(ComboBox cboSource, string[] strTexts, object[] oValues)
        {
            ListItem listItem;
            for(int i = 0; i < strTexts.Length; i++)
            {
                listItem = new ListItem(strTexts[i], oValues[i]);
                cboSource.Items.Add(listItem);
            }
        }
    }
}
